package com.aiwu;

import android.app.Activity;
import android.os.Environment;

import androidx.annotation.NonNull;

import com.aiwu.library.ui.act.AbsDownloadArchiveActivity;

import org.citra.citra_emu.utils.DirectoryInitialization;

import java.text.DecimalFormat;

/**
 * 下载存档
 */
public class DownloadArchiveActivity extends AbsDownloadArchiveActivity {
    @Override
    protected void onPermissionGranted() {
        DirectoryInitialization.start(this);
        super.onPermissionGranted();
    }

    private String getArchiveDir() {
        String userDirectory;
        if (DirectoryInitialization.getUserDirectory() != null) {
            userDirectory = DirectoryInitialization.getUserDirectory();
        } else {
            userDirectory = Environment.getExternalStorageDirectory().getAbsolutePath() + "/citra-emu";
        }
        return userDirectory+ "/states/";
    }

    @NonNull
    @Override
    public String getArchiveFilePath(String romName, String gameFilePath, int id) {
        DecimalFormat decimalFormat = new DecimalFormat("00");
        String slot = decimalFormat.format(id);
        return getArchiveDir() + romName + "." + slot + ".cst";
    }

    @NonNull
    @Override
    public String getArchivePicFilePath(String romName, String gameFilePath, int id) {
        return getArchiveDir() + romName + "_" + id + ".png";
    }

    @Override
    protected Class<? extends Activity> getEntryAct() {
        return EntryActivity.class;
    }
}
